package gui;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

import business.FormationBL;
import business.SeanceBL;
import business.SeanceSpecialeBL;

public class SeanceSpecialeUI extends JPanel {
	
	private int seanceSpecialeId;
	
	private AbstractPopupController popupController = new AbstractPopupController() {
		public JPopupMenu makePopup(int x, int y) {
			return new Popup();
		}
	};
	
	public SeanceSpecialeUI(int seanId, Color color, String nom, String salle) {
		
		seanceSpecialeId = seanId;
		
		this.setLayout(new GridLayout(3,0));
		this.setBackground(color);
		this.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.BLACK));

		this.addMouseListener(popupController);
		
		JLabel nomLabel = new JLabel(nom); nomLabel.setHorizontalAlignment(SwingConstants.CENTER); add(nomLabel);
		JLabel salleLabel = new JLabel(salle); salleLabel.setHorizontalAlignment(SwingConstants.CENTER); add(salleLabel);
		
	}

	public void setColor(Color color) {
		this.setBackground(color);
	}
	
	private class Popup extends JPopupMenu implements ActionListener {
		JMenuItem supprimer = new JMenuItem("Supprimer");
		
		public Popup() {
			supprimer.addActionListener(this);
			add(supprimer);
		}
		
		public void actionPerformed(ActionEvent e) {
			/*if (e.getSource() == modifier) {
				JOptionPane.showMessageDialog(this, "Modification");
			} else*/ if (e.getSource() == supprimer) {
				int retour = JOptionPane.showConfirmDialog(
					    this,
					    "Êtes vous sûr de vouloir supprimer la séance\n"+
					    //ensBL.getName()+" "+ensBL.getPrenom()+
					    " ?",
					    "Avertissement",
					    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
				if (retour == JOptionPane.YES_OPTION) {
					SeanceSpecialeBL seanceSpecialeBL = new SeanceSpecialeBL(seanceSpecialeId);
					seanceSpecialeBL.supprimerSeanceSpeciale();
				}

			}
			
		}
		
	}
	
}
